***************************************************
* This Stata do-file contains code that generates all tables and figures in main text and internet appendix of "The Value of Differing Points of View: Evidence from Financial Analysts' Geographic Diversity".	
* There are 8 required data input files (XXX.dta).
	*rfs_gp_replication_pseudo_data.dta is a 30% random sample of the dataset used in the paper for Tables 1 (panel A), 3, 4, 5, A2, A3, A4, and Figure 3
	*rfs_gp_rep_pseudo_data_ret_predict.dta is a 10% random sample of the dataset used in the paper for Table 2
	*rfs_gp_rep_pseudo_data_geo_divers.dta is a 5% random sample of the dataset used in the paper for Tables 1 (panel B), 6, 7, 8, A5, A6, A7, Figures 4, 5, and A1
	*rfs_gp_rep_pseudo_data_market_reaction.dta is a 5% random sample of the dataset used in the paper for Table 9 (columns 1 and 2)
	*rfs_gp_rep_pseudo_data_rec_revision.dta is a 15% random sample of the dataset used in the paper for Table 9 (columns 3 and4)
	*rfs_gp_rep_pseudo_data_ferc.dta is a 15% random sample of the dataset used in the paper for Table 10
	*rfs_gp_replication_pseudo_data_rolling_cc.dta is a 30% random sample of the dataset used in the paper for Table A1
	*scatter_replication.dta contains all data used in the paper for Figure 2
	* the code to produce figure 1 is run in python using 'ACC Figure 1.ipynb'
* all identifying variables have been masked and identified as masked variables in their labels.
* This program was run without errors in Stata 15.1. 
* The reghdfe command for STATA is currently available at: http://scorreia.com/software/reghdfe/
* the binscatter command for STATA can be installed using the following code: *ssc install binscatter
* Authors: Will Gerken & Marc Painter
* Date Modified: 10/27/2021
***************************************************


* Marc global paths
 	global tableOutput "E:\Dropbox\AnalystsCarCounts\ReplicationOutput"
 	global datafolder "E:\Dropbox\AnalystsCarCounts\ReplicationData"
 
* Will global paths
	*global tableOutput "D:\Dropbox\ActiveProjects\GerkenPainter\AnalystsCarCounts\ReplicationOutput"
	*global datafolder "D:\Dropbox\ActiveProjects\GerkenPainter\ReplicationData"


 
***************************************************
* Table 1 Panel A
* 
***************************************************
use $datafolder/rfs_gp_replication_pseudo_data, clear
	eststo clear
	estpost sum perc_msa error num_analysts num_analyst_msa hq no_store_nearby an_exp an_firm_exp for_age TURN12 ME BM if tagcq==1 & !mi(error) & yq<224, d
	* cc_diff would be errored down as above includes the zeros from no local stores, need to sum out separately
	estpost sum cc_diff if no_store_nearby==0 & tagcq==1 & !mi(error) & yq<224, d
	esttab using $tableOutput/sum_stats_oi.csv, replace cells("mean(fmt(3)) sd p25 p50 p75") title("Orbital Insight Sample")

	
***************************************************
* Table 2
* 
***************************************************
use $datafolder/rfs_gp_rep_pseudo_data_ret_predict, clear

eststo clear

eststo: reghdfe ev03_ret national_cc Size BE_ME PastReturn TURN12 l4_nat_cc  ln_analysts if tag_cq==1, absorb(tic2 yq) cluster(tic2 yq)
	estadd local controls "Yes"
	estadd local yqFE "Yes"
	estadd local firmFE "Yes"
eststo: reghdfe ev03_ret avg_ln_loc_cc Size BE_ME PastReturn TURN12 l4_nat_cc  ln_analysts if tag_cq==1, absorb(tic2 yq) cluster(tic2 yq)
	estadd local controls "Yes"
	estadd local yqFE "Yes"
	estadd local firmFE "Yes"
eststo: reghdfe ev03_ret national_cc avg_ln_loc_cc Size BE_ME PastReturn TURN12 l4_nat_cc  ln_analysts if tag_cq==1, absorb(tic2 yq) cluster(tic2 yq)	
	estadd local controls "Yes"
	estadd local yqFE "Yes"
	estadd local firmFE "Yes"	
* firm-msa-quarter level
eststo: reghdfe ev03_ret national_cc Size  BE_ME PastReturn TURN12  ln_analysts, absorb(tic2 yq) cluster(msa)
	estadd local controls "Yes"
	estadd local yqFE "Yes"
	estadd local firmFE "Yes"
eststo: reghdfe ev03_ret ln_loc_cc Size BE_ME PastReturn TURN12  ln_analysts, absorb(tic2 yq) cluster(msa)
	estadd local controls "Yes"
	estadd local yqFE "Yes"
	estadd local firmFE "Yes"
eststo: reghdfe ev03_ret national_cc ln_loc_cc Size BE_ME PastReturn TURN12  ln_analysts, absorb(tic2 yq) cluster(msa)
	estadd local controls "Yes"
	estadd local yqFE "Yes"
	estadd local firmFE "Yes"

 

esttab * using "$tableOutput/table2_return_prediction", replace label stats(controls firmFE yqFE r2 N, fmt(0 0 0 3 %9.0fc) labels("Controls" "Firm FE" "YQ FE" "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes indicate( `r(indicate_fe)') order(local_cc national_cc loc_cc_gro nat_cc_gro) keep(national_cc avg_ln_loc_cc ln_loc_cc)    nomtitles star(* 0.10 ** 0.05 *** 0.01) mgroups("Earnings Announcement Return", span  prefix(\multicolumn{@span}{c}{)suffix(}))  


***************************************************
* Table 3
* 
***************************************************

use $datafolder/rfs_gp_replication_pseudo_data, clear

eststo clear
eststo main_1 : reghdfe error cc_diff ln_nat_cc no_store_nearby hq ln_msa_gdp TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(firm yq) cluster(msa)
	estadd local yqFE "Yes"
	estadd local firmFE "Yes"
eststo main_2 : reghdfe error cc_diff no_store_nearby hq ln_msa_gdp TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(firm##yq) cluster(msa)
	estadd local yqFE "Subsumed"
	estadd local firmFE "Subsumed"
	estadd local firmyqFE "Yes"		
eststo main_3 : reghdfe error cc_diff no_store_nearby hq ln_msa_gdp TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(firm##yq msa) cluster(msa)
	estadd local yqFE "Subsumed"
	estadd local firmFE "Subsumed"
	estadd local firmyqFE "Yes"	
	estadd local msaFE "Yes"	
eststo main_4 : reghdfe error cc_diff no_store_nearby hq ln_msa_gdp TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(firm##yq msa##yq ) cluster(msa)
  	estadd local yqFE "Subsumed"
	estadd local firmFE "Subsumed"
	estadd local firmyqFE "Yes"	
	estadd local msaFE "Subsumed"	
	estadd local msayqFE "Yes"	
	
esttab main_1 main_2 main_3 main_4 using "$tableOutput/table2_error_cc", replace label stats(yqFE firmFE firmyqFE msaFE msayqFE r2 N, fmt(0 0 0 0 0 3 %9.0fc) labels("YQ FE" "Firm FE" "Firm\(\times\)YQ FE" "MSA FE" "MSA\(\times\)YQ FE"  "\(R^{2}\)" "Observations")) noomitted b(4) se(4) varwidth(40) booktabs nonotes  order(cc_diff TURN12 Size BM ln_analysts ln_nat_cc ln_msa_gdp no_store_nearby hq    experience firm_experience ln_age) keep(cc_diff no_store_nearby hq ln_nat_cc ln_msa_gdp TURN12 Size BM ln_analysts experience firm_experience ln_age)    nomtitles star(* 0.10 ** 0.05 *** 0.01)  substitute(\_ _)
 


***************************************************
* Table 4
* 
***************************************************
eststo clear

eststo hetero1: reghdfe error cc_diff cc_diff_zint_exp hq no_store_nearby TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb( msa##yq  firm##yq) cluster(msa)
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"	
	estadd local msayqFE "Yes"
eststo hetero2: reghdfe error cc_diff cc_diff_zint_analysts  hq no_store_nearby TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(msa##yq  firm##yq) cluster(msa)
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"	
	estadd local msayqFE "Yes"
eststo hetero3: reghdfe error cc_diff cc_diff_zint_msa hq no_store_nearby TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(msa##yq  firm##yq) cluster(msa)
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"	
	estadd local msayqFE "Yes"
eststo hetero4: reghdfe error cc_diff sat_release cc_diff_sat_release hq no_store_nearby TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(msa##yq  firm##yq) cluster(msa)	
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"	
	estadd local msayqFE "Yes"
eststo hetero5: reghdfe error cc_diff high8k cc_diff_high8k  hq no_store_nearby TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb( msa##yq  firm##yq) cluster(msa)
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"	
	estadd local msayqFE "Yes"
eststo hetero6: reghdfe error  cc_diff_early cc_diff_middle cc_diff_late hq no_store_nearby TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb( msa##yq  firm##yq) cluster(msa)
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"	
	estadd local msayqFE "Yes"


esttab hetero* using "$tableOutput/table4_alt", replace label stats(controls firmyqFE msayqFE r2 N, fmt(0 0 0 3 %9.0fc) labels("Controls"  "Firm\(\times\)YQ FE"  "MSA\(\times\)YQ FE" "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes   order(cc_diff cc_diff_zint_exp cc_diff_zint_analysts cc_diff_zint_msa cc_diff_sat_release    cc_diff_high8k cc_diff_early cc_diff_middle cc_diff_late) keep(cc_diff cc_diff_zint_exp cc_diff_zint_analysts cc_diff_zint_msa cc_diff_sat_release  cc_diff_high8k cc_diff_early cc_diff_middle cc_diff_late)    nomtitles star(* 0.10 ** 0.05 *** 0.01) 


  
***************************************************
* Table 5
* 
***************************************************
eststo clear

eststo robust1: reghdfe error cc_diff no_store_nearby hq TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(firm##yq msa##yq amaskcd##firm) cluster(msa)
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"
	estadd local msayqFE "Yes"	
	estadd local amaskcdfirmFE "Yes"
	estadd local sample "Full"		
eststo robust2: reghdfe error cc_diff no_store_nearby hq TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(firm##yq msa##yq amaskcd##firm amaskcd##yq) cluster(msa)
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"
	estadd local msayqFE "Yes"	
	estadd local amaskcdfirmFE "Yes"
	estadd local amaskcdyqFE "Yes"
	estadd local sample "Full"	
eststo robust3: reghdfe error cc_diff  hq no_store_nearby TURN12 Size BM ln_analysts experience firm_experience ln_age if nyc != 1, absorb(msa##yq firm##yq) cluster(msa)
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"
	estadd local msayqFE "Yes"	
	estadd local sample "No NYC"
 eststo robust4: reghdfe error cc_diff cc_diff_large_area  no_store_nearby hq ln_msa_gdp TURN12 Size BM ln_analysts experience firm_experience ln_age, absorb(firm##yq msa##yq) cluster(msa)
  estadd local controls "Yes"
	estadd local firmyqFE "Yes"
	estadd local msayqFE "Yes"
	estadd local sample "Full"	
eststo robust5: reghdfe error cc_diff hq no_store_nearby TURN12 Size BM ln_analysts experience firm_experience ln_age if msa_store_count_qtrly >= 5 & no_store_nearby == 0, absorb(msa##yq firm##yq) cluster(msa)
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"
	estadd local msayqFE "Yes"	
	estadd local sample "High Image"
eststo robust6: reghdfe error cc_diff_high cc_diff_mid cc_diff_low hq no_store_nearby TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(msa##yq  firm##yq) cluster(msa)
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"
	estadd local msayqFE "Yes"
	estadd local sample "Full"
 
esttab robust* using "$tableOutput/table5_robust", replace label stats(controls firmyqFE msayqFE amaskcdfirmFE amaskcdyqFE sample  r2 N, fmt(0 0 0 0 0 0 3 %9.0fc) labels("Controls"  "Firm\(\times\)YQ FE"  "MSA\(\times\)YQ FE"  "Analyst\(\times\)Firm FE" "Analyst\(\times\)YQ FE" "Sample" "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes order(cc_diff cc_diff_large_area cc_diff_high cc_diff_mid cc_diff_low ) keep(cc_diff cc_diff_large_area cc_diff_high cc_diff_mid cc_diff_low)    nomtitles star(* 0.10 ** 0.05 *** 0.01) 
 
 
 
			
****************************************************
* Table 1 Panel B
*
****************************************************
use $datafolder/rfs_gp_rep_pseudo_data_geo_divers, clear
	eststo clear
	eststo: sum cons_error bid_ask_spread_1_1 dispers_index num_analysts num_msa an_exp an_firm_exp for_age TURN12 ME BM if tag==1, d
	eststo: sum unique if tag_acq==1,d
	esttab using $tableOutput/sum_stats_full.csv, replace cells("mean(fmt(3)) sd p25 p50 p75") title("Full Sample")

	
***************************************************
* Table 6 Panel A
* 
***************************************************  
global controls "num_analysts TURN12  BM  Size firm_age no_age high_inst_ownership "
eststo clear
eststo oiconsensus1:    reghdfe cons_error dispers_index $controls if tagcq1 ==1 & OI==1, absorb(sic2 yq) cluster(tid )
	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
eststo oiconsensus2:    reghdfe cons_error num_msa  $controls if tagcq1 ==1 & OI==1, absorb(sic2 num_analysts  yq) cluster(tid )
	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
	estadd local num_analysts "Yes"
eststo oiconsensus3:    reghdfe bid_ask_spread_1_1 dispers_index  $controls if tagcq1 ==1 & OI==1 , absorb(sic2 yq) cluster(tid )
	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
eststo oiconsensus4:    reghdfe bid_ask_spread_1_1 num_msa  $controls if tagcq1 ==1 & OI==1, absorb(sic2 num_analysts  yq) cluster(tid )
	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
	estadd local num_analysts "Yes"
esttab oiconsensus* using "$tableOutput/table_consensus_OI", replace  keep(dispers_index num_msa) label stats(controls  sic2  yq num_analysts r2 N, fmt(0 0 0 0 3 %9.0fc) labels("Controls" "Industry FE" "YQ FE" "Number of Analysts FE" "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes      nomtitles star(* 0.10 ** 0.05 *** 0.01) mgroups("Consensus Abs(Error)" "Bid-ask Spread", pattern(1 0  1  0) span prefix(\multicolumn{@span}{c}{) suffix(}) ) 

***************************************************
* Table 6 Panel B
* 
*************************************************** 
global controls "num_analysts TURN12  BM  Size firm_age no_age high_inst_ownership "

* Analyst Geog. Dispersion on Forecast error and Spread
  eststo clear
  eststo consensus1:    reghdfe cons_error dispers_index   $controls if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
	
  eststo consensus2:    reghdfe cons_error num_msa    $controls if tagcq1 ==1 , absorb(sic2 num_analysts  yq) cluster(tid )
	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
	estadd local num_analysts "Yes"
  eststo consensus3:    reghdfe bid_ask_spread_1_1 dispers_index  $controls if tagcq1 ==1  , absorb(sic2 yq) cluster(tid )
	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
	
  eststo consensus4:    reghdfe bid_ask_spread_1_1 num_msa    $controls if tagcq1 ==1 , absorb(sic2 num_analysts  yq) cluster(tid )
	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
	estadd local num_analysts "Yes"

esttab consensus* using "$tableOutput/table6_consensus", replace  keep(dispers_index num_msa) label stats(controls  sic2  yq num_analysts r2 N, fmt(0 0 0 0 3 %9.0fc) labels("Controls" "Industry FE" "YQ FE" "Number of Analysts FE" "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes      nomtitles star(* 0.10 ** 0.05 *** 0.01) mgroups("Consensus Abs(Error)" "Bid-ask Spread", pattern(1 0  1  0) span prefix(\multicolumn{@span}{c}{) suffix(}) ) 
 



  



***************************************************
* Figure 4
* 
*************************************************** 
* Panel A
bys nm6: sum cons_error
* Panel B
bys nm6: sum bid_ask_spread_1_1
* Panel C	
	reghdfe cons_error i.nm6   TURN12  BM  Size firm_age no_age high_inst_ownership if tagcq1 ==1 , absorb(sic2 num_analysts  yq) cluster(tid )
* Panel D
	reghdfe bid_ask_spread_1_1 i.nm6   TURN12  BM  Size firm_age no_age high_inst_ownership if tagcq1 ==1 , absorb(sic2 num_analysts  yq) cluster(tid )


***************************************************
* Table 7
* 
*************************************************** 
* Latex note - rename variable each time so the output to Latex is succinct
	* Consensus Forecast Error
	eststo clear
		rename small fc
		gen dispers_index_fc = dispers_index*fc
		eststo: reghdfe cons_error dispers_index fc dispers_index_fc  $controls  if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
			estadd local controls "Yes"
			estadd local sic2  "Yes"
			estadd local yq "Yes"
	
			rename fc small
			drop dispers_index_fc
		rename young fc
		gen dispers_index_fc = dispers_index*fc
		eststo: reghdfe cons_error dispers_index fc dispers_index_fc  $controls  if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
			estadd local controls "Yes"
			estadd local sic2  "Yes"
			estadd local yq "Yes"
	
			rename fc young
			drop dispers_index_fc
		rename low_prc fc
		gen dispers_index_fc = dispers_index*fc
		eststo: reghdfe cons_error dispers_index fc dispers_index_fc $controls  if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
			estadd local controls "Yes"
			estadd local sic2  "Yes"
			estadd local yq "Yes"
	
			rename fc low_prc
			drop dispers_index_fc
		rename z_widiorisk fc
		gen dispers_index_fc = dispers_index*fc
		eststo: reghdfe cons_error dispers_index fc dispers_index_fc $controls  if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
			estadd local controls "Yes"
			estadd local sic2  "Yes"
			estadd local yq "Yes"
	
			rename fc z_widiorisk
			drop dispers_index_fc
		rename z_wreturnskew fc
		gen dispers_index_fc = dispers_index*fc
		eststo: reghdfe cons_error dispers_index fc dispers_index_fc $controls if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
			estadd local controls "Yes"
			estadd local sic2  "Yes"
			estadd local yq "Yes"
	
			rename fc z_wreturnskew
			drop dispers_index_fc	
		rename z_wrd_pmm fc
		gen dispers_index_fc = dispers_index*fc
		eststo: reghdfe cons_error dispers_index fc dispers_index_fc no_rd_pmm $controls  if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
			estadd local controls "Yes"
			estadd local sic2  "Yes"
			estadd local yq "Yes"
			label var dispers_index "MSA Dispersion Index"
	label var fc "Firm Chararacteristic"
	label var dispers_index_fc "MSA Disp Index \(\times\) Firm Char."


	esttab * using "$tableOutput/harder_to_value_stocks_consensus", replace keep(dispers_index fc dispers_index_fc) label stats(controls sic2  yq r2 N, fmt(0 0 0 3 %9.0fc) labels("Controls" "Industry FE"   "YQ FE"  "\(R^{2}\)" "Observations"))	b(3) se(3) varwidth(40) booktabs nonotes nomtitles star(* 0.10 ** 0.05 *** 0.01) mgroups("Small" "Young" "LowPrice" "IVOL" "Skew" "R\&D", pattern(1 1 1 1 1 1) span prefix(\multicolumn{@span}{c}{) suffix(}) ) 
	rename fc z_wrd_pmm
	drop dispers_index_fc
	
	* Bid ask spread
	eststo clear
		rename small fc
		gen dispers_index_fc = dispers_index*fc
		eststo: reghdfe bid_ask_spread_1_1 dispers_index fc dispers_index_fc  $controls if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
			estadd local controls "Yes"
			estadd local sic2  "Yes"
			estadd local yq "Yes"
			rename fc small
			drop dispers_index_fc
		rename young fc
		gen dispers_index_fc = dispers_index*fc
		eststo: reghdfe bid_ask_spread_1_1 dispers_index fc dispers_index_fc no_age $controls  if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
			estadd local controls "Yes"
			estadd local sic2  "Yes"
			estadd local yq "Yes"
			rename fc young
			drop dispers_index_fc
		rename low_prc fc
		gen dispers_index_fc = dispers_index*fc
		eststo: reghdfe bid_ask_spread_1_1 dispers_index fc dispers_index_fc $controls  if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
			estadd local controls "Yes"
			estadd local sic2  "Yes"
			estadd local yq "Yes"
			rename fc low_prc
			drop dispers_index_fc
		rename z_widiorisk fc
		gen dispers_index_fc = dispers_index*fc
		eststo: reghdfe bid_ask_spread_1_1 dispers_index fc dispers_index_fc $controls if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
			estadd local controls "Yes"
			estadd local sic2  "Yes"
			estadd local yq "Yes"
			rename fc z_widiorisk
			drop dispers_index_fc
		rename z_wreturnskew fc
		gen dispers_index_fc = dispers_index*fc
		eststo: reghdfe bid_ask_spread_1_1 dispers_index fc dispers_index_fc $controls if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
			estadd local controls "Yes"
			estadd local sic2  "Yes"
			estadd local yq "Yes"
			rename fc z_wreturnskew
			drop dispers_index_fc	
		rename z_wrd_pmm fc
		gen dispers_index_fc = dispers_index*fc
		eststo: reghdfe bid_ask_spread_1_1 dispers_index fc dispers_index_fc no_rd_pmm $controls  if tagcq1 ==1 , absorb(sic2 yq) cluster(tid )
			estadd local controls "Yes"
			estadd local sic2  "Yes"
			estadd local yq "Yes"
			
	label var dispers_index "MSA Dispersion Index"
	label var fc "Firm Chararacteristic"
	label var dispers_index_fc "MSA Disp Index \(\times\) Firm Char."
	estfe *, labels(  sic2  "Industry FE" yq "YQ FE" num_analysts "Number of Analysts FE")
	
	esttab * using "$tableOutput/harder_to_value_stocks_spread", replace keep(dispers_index fc dispers_index_fc) label stats(controls sic2  yq r2 N, fmt(0 0 0 3 %9.0fc) labels("Controls" "Industry FE"   "YQ FE" "\(R^{2}\)" "Observations")) b(3) se(3) varwidth(40) booktabs nonotes nomtitles star(* 0.10 ** 0.05 *** 0.01) mgroups("Small" "Young" "LowPrice" "IVOL" "Skew" "R\&D", pattern(1 1 1 1 1 1) span prefix(\multicolumn{@span}{c}{) suffix(}) ) 
	rename fc z_wrd_pmm
	drop dispers_index_fc

	
	
	

***************************************************
* Table 8
* 
*************************************************** 
 
* Broker merger/closer shock   

 global controls "num_analysts TURN12  BM  expSize  firm_age  high_inst_ownership "

eststo clear
eststo:    reghdfe cons_error dispers_index  $controls   if tagcq1 ==1 , absorb(tid yq) cluster(tid )
	estadd local controls "Yes"
	estadd local firmFE "Yes"
	estadd local yq "Yes"
eststo:    reghdfe cons_error num_msa   $controls   if tagcq1 ==1 , absorb(tid yq) cluster(tid )    
	estadd local controls "Yes"
	estadd local firmFE "Yes"
	estadd local yq "Yes"
eststo:    reghdfe cons_error  lost_msa  num_msa   $controls   if tagcq1 ==1 &  lhe==1  , absorb(sic2 yq) cluster(tid )
    	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
eststo:    reghdfe bid_ask_spread_1_1 dispers_index  num_analysts   $controls  if tagcq1 ==1 , absorb(tid yq) cluster(tid )
    	estadd local controls "Yes"
	estadd local firmFE "Yes"
	estadd local yq "Yes"
eststo:    reghdfe bid_ask_spread_1_1 num_msa  num_analysts   $controls   if tagcq1 ==1 , absorb(tid yq) cluster(tid )    
    	estadd local controls "Yes"
	estadd local firmFE "Yes"
	estadd local yq "Yes"
eststo:    reghdfe bid_ask_spread_1_1  lost_msa  num_msa    $controls   if tagcq1 ==1 &  lhe==1  , absorb(sic2 yq) cluster(tid )
    	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
    
 
    	esttab * using "$tableOutput/table7_consensus", replace label keep(dispers_index num_msa lost_msa) stats(controls  firmFE sic2  yq r2 N, fmt(0 0 0 0 3 %9.0fc) labels("Controls" "Firm FE" "Industry FE" "YQ FE" "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes     nomtitles star(* 0.10 ** 0.05 *** 0.01) mgroups("Cons Abs(Error)" "Bid-ask Spread", pattern(1 0 0 1 0 0) span prefix(\multicolumn{@span}{c}{) suffix(}) )  


***************************************************
* Table A-7 Analyst Geographic Dispersion, Consensus Forecasts, and Firm Liquidity around Satellite Data Release
* 
*************************************************** 

global controls "num_analysts TURN12  BM  Size firm_age high_inst_ownership "

eststo clear
eststo:    reghdfe cons_error dispers_index sat_release dispers_index_sat_release $controls  if tagcq1 ==1 & OI==1, absorb(sic2 yq) cluster(tid )
    	estadd local controls "Yes"
	estadd local sic2 "Yes"
	estadd local yq "Yes"
eststo:    reghdfe cons_error num_msa sat_release num_msa_sat_release  $controls if tagcq1 ==1 & OI==1, absorb(sic2 num_analysts  yq) cluster(tid )
    	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
	estadd local num_analysts "Yes"
eststo:    reghdfe bid_ask_spread_1_1 dispers_index sat_release dispers_index_sat_release  num_analysts $controls  if tagcq1 ==1 & OI==1 , absorb(sic2 yq) cluster(tid )
    	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
eststo:    reghdfe bid_ask_spread_1_1 num_msa sat_release num_msa_sat_release    $controls if tagcq1 ==1 & OI==1, absorb(sic2 num_analysts  yq) cluster(tid )
    	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
	estadd local num_analysts "Yes"
 

esttab * using "$tableOutput/table_OI_dispersion_release", replace keep(dispers_index  dispers_index_sat_release num_msa num_msa_sat_release)	order(dispers_index num_msa  dispers_index_sat_release  num_msa_sat_release) label stats(controls sic2  yq num_analysts r2 N, fmt(0 0 0 0 3 %9.0fc) labels("Controls"  "Industry FE" "YQ FE"  "Number of Analysts FE" "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes nomtitles star(* 0.10 ** 0.05 *** 0.01) mgroups("Consensus Abs(Error)" "Bid-ask Spread", pattern(1 0  1  0) span prefix(\multicolumn{@span}{c}{) suffix(}) ) 
	   


***************************************************
* Figure 5
***************************************************

forvalues i = 1(1)17 {
	reghdfe cons_error dispers_index   $controls if tagcq1 ==1 & ff17==`i', absorb( yq) cluster(tid )
}
forvalues i = 1(1)17 {
	reghdfe bid_ask_spread_1_1 dispers_index   $controls   if tagcq1 ==1 & ff17==`i', absorb( yq) cluster(tid )
}

***************************************************
* Figure A-1
***************************************************
	gen y2000 = year - 2000
		replace y2000 = 0 if y2000<0
	  	reghdfe cons_error c.dispers_index#y2000 $controls  if tagcq1 ==1, absorb(sic2 yq) cluster(tid )
	  	reghdfe bid_ask_spread_1_1 c.dispers_index#y2000  $controls  if tagcq1 ==1, absorb(sic2 yq) cluster(tid )



***************************************************
* Table A-6 Alternate Region
* 
*************************************************** 
global controls "num_analysts TURN12  BM  Size firm_age high_inst_ownership "
eststo clear
eststo:    reghdfe cons_error dispers_index_region   $controls if tagcq1 ==1, absorb(sic2 yq) cluster(tid )
    	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
eststo:    reghdfe cons_error num_region    $controls if tagcq1 ==1, absorb(sic2 num_analysts  yq) cluster(tid )
    	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
	estadd local num_analysts "Yes"
eststo:    reghdfe bid_ask_spread_1_1  dispers_index_region   $controls  if tagcq1 ==1  , absorb(sic2 yq) cluster(tid )
    	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
eststo:    reghdfe bid_ask_spread_1_1 num_region     $controls if tagcq1 ==1,  absorb(sic2 num_analysts  yq) cluster(tid )
    	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
	estadd local num_analysts "Yes"

esttab * using "$tableOutput/table_otherregion", replace keep(dispers_index_region num_region    )	order(dispers_index_region num_region   ) label stats(controls sic2  yq num_analysts r2 N, fmt(0 0 0 0 3 %9.0fc) labels("Controls"  "Industry FE" "YQ FE"  "Number of Analysts FE" "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes nomtitles star(* 0.10 ** 0.05 *** 0.01) mgroups("Consensus Abs(Error)" "Bid-ask Spread", pattern(1 0 1 0) span prefix(\multicolumn{@span}{c}{) suffix(}) ) 



 

***************************************************
* Table 9
* 
*************************************************** 
use $datafolder/rfs_gp_rep_pseudo_data_market_reaction, clear	

**** REGRESSIONS ****
eststo clear
eststo: reghdfe abnormal_return_1_1 diverse z_fcast_chg_stk_qtr  diverse_z_fcast_chg_stk_qtr an_hq_msa num_analysts TURN12  BM  Size ln_age ln_nstocks ln_totexp ln_stockexp all_star if num_analysts > 1, abs(tid##yq) cluster( tid)
  estadd local controls "Yes"
	estadd local firmyqFE "Yes"
 
eststo: reghdfe abnormal_return_1_1 diverse z_fcast_chg_stk_qtr diverse_z_fcast_chg_stk_qtr an_hq_msa num_analysts TURN12  BM  Size ln_age ln_nstocks ln_totexp ln_stockexp all_star if num_analysts > 1, abs(amaskcd tid##yq) cluster(tid)
  estadd local controls "Yes"
	estadd local firmyqFE "Yes"	
estadd local amaskcd "Yes"


	
use $datafolder/rfs_gp_rep_pseudo_data_rec_revision, clear

eststo: reghdfe abnormal_return_1_1 diverse rec3_chg diverse_rec3_chg an_hq_msa num_analysts TURN12  BM  Size ln_nstocks ln_totexp ln_stockexp all_star if num_analysts > 1, abs(tid##yq) cluster( tid)
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"
eststo: reghdfe abnormal_return_1_1 diverse rec3_chg diverse_rec3_chg an_hq_msa num_analysts TURN12  BM  Size ln_nstocks ln_totexp ln_stockexp all_star if num_analysts > 1, abs(amaskcd tid##yq) cluster(tid)
	estadd local controls "Yes"
	estadd local firmyqFE "Yes"
	estadd local amaskcd "Yes"	
	
esttab * using "$tableOutput/table_rev_car", replace label stats(controls firmyqFE amaskcd r2 N, fmt(0 0 0 3 %9.0fc) labels("Controls" "Firm\(\times\)YQ FE" "Analyst FE" "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes  order(diverse z_fcast_chg_stk_qtr diverse_z_fcast_chg_stk_qtr rec3_chg diverse_rec3_chg) keep(diverse z_fcast_chg_stk_qtr diverse_z_fcast_chg_stk_qtr rec3_chg diverse_rec3_chg)    nomtitles star(* 0.10 ** 0.05 *** 0.01) mgroups("Market Response to Revision", span  prefix(\multicolumn{@span}{c}{)suffix(}))  
	 




********************************************************************************
*TABLE 10
********************************************************************************
 
use $datafolder/rfs_gp_rep_pseudo_data_ferc, clear	
eststo clear

eststo: reghdfe wret_ann_vw wfwd_earn high_num_msa fwd_earn_high_msa wf_ret_ann_vw log_mkt_cap num_analyst ass_gro loss  ROA  , a(firm fyear) cluster(firm)	
		estadd local controls "Yes"
		estadd local firmFE "Yes"
		estadd local yearFE "Yes"
eststo: reghdfe wret_ann_vw wfwd_earn high_num_msa fwd_earn_high_msa wearn earn_high_msa wlag_earn lag_earn_high_msa wf_ret_ann_vw log_mkt_cap num_analyst ass_gro loss  ROA , a(firm fyear) cluster(firm)	
		estadd local controls "Yes"
		estadd local firmFE "Yes"
		estadd local yearFE "Yes"
eststo: reghdfe wret_ann_vw wfwd_earn high_disp_index fwd_earn_high_disp wf_ret_ann_vw log_mkt_cap num_analyst ass_gro loss  ROA  , a(firm fyear) cluster(firm)	
		estadd local controls "Yes"
		estadd local firmFE "Yes"
		estadd local yearFE "Yes"
eststo: reghdfe wret_ann_vw wfwd_earn high_disp_index fwd_earn_high_disp wearn earn_high_disp wlag_earn lag_earn_high_disp wf_ret_ann_vw log_mkt_cap num_analyst ass_gro loss  ROA , a(firm fyear) cluster(firm)	
		estadd local controls "Yes"
		estadd local firmFE "Yes"
		estadd local yearFE "Yes"

		
	esttab * using "$tableOutput/table_ferc", replace label stats(controls firmFE yearFE r2 N, fmt(0 0 0 3 %9.0fc) labels("Controls" "Firm FE"   "Year FE" "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes   order(wfwd_earn high_num_msa fwd_earn_high_msa high_disp_index fwd_earn_high_disp wearn wlag_earn earn_high_msa  lag_earn_high_msa   earn_high_disp  lag_earn_high_disp ) keep(wfwd_earn high_num_msa fwd_earn_high_msa wearn earn_high_msa wlag_earn lag_earn_high_msa high_disp_index fwd_earn_high_disp  fwd_earn_high_disp  lag_earn_high_disp)    nomtitles star(* 0.10 ** 0.05 *** 0.01) mgroups("Annual Stock Return", span  prefix(\multicolumn{@span}{c}{)suffix(}))  


********************************************************************************
*Appendix table 2 - Alternate Measure of Car Counts

use $datafolder/rfs_gp_replication_pseudo_data, clear
 	eststo clear
 	
 	 
 	
	eststo main_1 : reghdfe error ln_loc_cc ln_nat_cc no_store_nearby hq ln_msa_gdp TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(firm yq) cluster(msa)
		estadd local yqFE "Yes"
		estadd local firmFE "Yes"
 	eststo main_2 : reghdfe error ln_loc_cc no_store_nearby hq ln_msa_gdp TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(firm##yq) cluster(msa)
		estadd local yqFE "Subsumed"
		estadd local firmFE "Subsumed"
		estadd local firmyqFE "Yes"		
 	eststo main_3 : reghdfe error ln_loc_cc no_store_nearby hq ln_msa_gdp TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(firm##yq msa) cluster(msa)
 			estadd local yqFE "Subsumed"
			estadd local firmFE "Subsumed"
		estadd local firmyqFE "Yes"	
		estadd local msaFE "Yes"	
 	eststo main_4 : reghdfe error ln_loc_cc no_store_nearby hq ln_msa_gdp TURN12 Size BM ln_analysts experience firm_experience ln_age , absorb(firm##yq msa##yq ) cluster(msa)
  			estadd local yqFE "Subsumed"
			estadd local firmFE "Subsumed"
		estadd local firmyqFE "Yes"	
		estadd local msaFE "Subsumed"	
		estadd local msayqFE "Yes"	
	esttab main_1 main_2 main_3 main_4 using "$tableOutput/scaled1", replace label stats(yqFE firmFE firmyqFE msaFE msayqFE r2 N, fmt(0 0 0 0 0 3 %9.0fc) labels("YQ FE" "Firm FE" "Firm\(\times\)YQ FE" "MSA FE" "MSA\(\times\)YQ FE"  "\(R^{2}\)" "Observations")) noomitted b(4) se(4) varwidth(40) booktabs nonotes  order(cc TURN12 Size BM ln_analysts ln_nat_cc ln_msa_gdp no_store_nearby hq   TURN12 Size BM ln_analysts experience firm_experience ln_age) keep(cc  no_store_nearby hq ln_nat_cc ln_msa_gdp  experience firm_experience ln_age)    nomtitles star(* 0.10 ** 0.05 *** 0.01)  substitute(\_ _)



 
********************************************************************************
************** Table A-3 Alternate Clustering Approaches ***************
eststo clear  	 
	
eststo cluster_0 : reghdfe error cc_diff no_store_nearby hq  experience firm_experience ln_age , absorb(firm##yq msa##yq ) cluster(msa)
 		estadd local firmyqFE "Yes"	
 		estadd local msayqFE "Yes"	
 	 	estadd local cluster "MSA"
eststo cluster_1 : reghdfe error cc_diff no_store_nearby hq  experience firm_experience ln_age , absorb(firm##yq msa##yq ) cluster(yq)
 		estadd local firmyqFE "Yes"	
 		estadd local msayqFE "Yes"	
 	 	estadd local cluster "YQ"
eststo cluster_2 : reghdfe error cc_diff no_store_nearby hq  experience firm_experience ln_age , absorb(firm##yq msa##yq ) cluster(firm)
 		estadd local firmyqFE "Yes"	
 		estadd local msayqFE "Yes"	
 	 	estadd local cluster "Firm"	
eststo cluster_3 : reghdfe error cc_diff no_store_nearby hq  experience firm_experience ln_age , absorb(firm##yq msa##yq ) cluster(amaskcd)
 		estadd local firmyqFE "Yes"	
 		estadd local msayqFE "Yes"	
 	 	estadd local cluster "Analyst"	
eststo cluster_4 : reghdfe error cc_diff no_store_nearby hq  experience firm_experience ln_age , absorb(firm##yq msa##yq ) cluster(msa yq)
 		estadd local firmyqFE "Yes"	
 		estadd local msayqFE "Yes"	
 	 	estadd local cluster "MSA\&YQ"	
eststo cluster_5 : reghdfe error cc_diff no_store_nearby hq  experience firm_experience ln_age , absorb(firm##yq msa##yq ) cluster(firm yq)
 		estadd local firmyqFE "Yes"	
 		estadd local msayqFE "Yes"	
 	 	estadd local cluster "Firm\&YQ"	
eststo cluster_6 : reghdfe error cc_diff no_store_nearby hq  experience firm_experience ln_age , absorb(firm##yq msa##yq ) cluster(amaskcd yq)
 		estadd local firmyqFE "Yes"	
 		estadd local msayqFE "Yes"	
 	 	estadd local cluster "Analyst\&YQ"	
		
 	esttab cluster_* using "$tableOutput/clustering_table4", replace label stats(cluster firmyqFE   msayqFE r2 N, fmt(0 0 0   3 %9.0fc) labels("Clustering"   "Firm\(\times\)YQ FE"    "MSA\(\times\)YQ FE"  "\(R^{2}\)" "Observations")) noomitted b(4) se(4) varwidth(40) booktabs nonotes  order(cc_diff no_store_nearby hq ln_msa_gdp ln_nat_cc TURN12 Size BM ln_analysts experience firm_experience ln_age) keep(cc_diff no_store_nearby hq ln_nat_cc ln_msa_gdp TURN12 Size BM ln_analysts experience firm_experience ln_age)    nomtitles star(* 0.10 ** 0.05 *** 0.01)  substitute(\_ _)


********************************************************************************
************** Table A-4 Local Economic Effects Robustness table ***************
********************************************************************************
	

eststo clear

	eststo: reghdfe error cc_diff msa_ccd only_msa_firm no_store_nearby hq TURN12 Size BM ln_analysts experience firm_experience ln_age, absorb(firm##yq msa) cluster(msa)
			estadd local controls "Yes"
			estadd local firmyqFE "Yes"
			estadd local msaFE "Yes"
	eststo: reghdfe error cc_diff no_store_nearby hq msa_sic4_ccd only_sic4_firm TURN12 Size BM ln_analysts experience firm_experience ln_age, absorb(firm##yq msa) cluster(msa)
			estadd local controls "Yes"
			estadd local firmyqFE "Yes"
			estadd local msaFE "Yes"
	
 

esttab * using "$tableOutput/table_msa_perf", replace label stats(controls firmyqFE msaFE r2 N, fmt(0 0 0 3 %9.0fc) labels("Controls" "Firm\(\times\)YQ FE" "MSA FE" "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes   order(cc_diff msa_ccd msa_sic4_ccd) keep(cc_diff msa_ccd msa_sic4_ccd)    nomtitles star(* 0.10 ** 0.05 *** 0.01) mgroups("Error", span  prefix(\multicolumn{@span}{c}{)suffix(}))  
	
	

	
********************************************************************************
* Table A-1: Rolling Car Counts
********************************************************************************
use $datafolder/rfs_gp_replication_pseudo_data_rolling_cc, clear
	
eststo clear
eststo: reghdfe error ccd_30_vw no_store_nearby hq TURN12 Size BM ln_analysts experience firm_experience ln_age, absorb(firm##yq msa##yq) cluster(msa)
			estadd local controls "Yes"
			estadd local firmyqFE "Yes"
			estadd local msayqFE "Yes"
eststo: reghdfe error ccd_60_vw no_store_nearby hq TURN12 Size BM ln_analysts experience firm_experience ln_age, absorb(firm##yq msa##yq) cluster(msa)
			estadd local controls "Yes"
			estadd local firmyqFE "Yes"
			estadd local msayqFE "Yes"

eststo: reghdfe error ccd_90_vw no_store_nearby hq TURN12 Size BM ln_analysts experience firm_experience ln_age, absorb(firm##yq msa##yq) cluster(msa)
			estadd local controls "Yes"
			estadd local firmyqFE "Yes"
			estadd local msayqFE "Yes"	

esttab * using "$tableOutput/table_rolling_ccd", replace label stats(controls firmyqFE msaFE msayqFE r2 N, fmt(0 0 0 0 3 %9.0fc) labels("Controls" "Firm\(\times\)YQ FE" "MSA FE" "MSA\(\times\)YQ FE" "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes  order(ccd_30_vw ccd_60_vw ccd_90_vw) keep(ccd_30_vw ccd_60_vw ccd_90_vw)    nomtitles star(* 0.10 ** 0.05 *** 0.01) 




********************************************************************************
* Table A-5 Ethnic versus Geographic Diversity
********************************************************************************
use  $datafolder/rfs_gp_rep_pseudo_data_geo_divers, clear			
			
			
	global controls "num_analysts TURN12  BM  Size firm_age high_inst_ownership "		
 
  eststo clear
  eststo v1:    reghdfe cons_error dispers_index  $controls  if tagcq1 ==1 & num_nationality==1, absorb(sic2 yq) cluster(tid )
 	estadd local controls "Yes"
 	estadd local sic2  "Yes"
	estadd local yq "Yes"
 eststo:    reghdfe cons_error num_msa   $controls if tagcq1 ==1 & num_nationality==1, absorb(sic2 num_analysts  yq) cluster(tid )
	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
	estadd local num_analysts "Yes"
 eststo:    reghdfe bid_ask_spread_1_1 dispers_index    $controls  if tagcq1 ==1  & num_nationality==1, absorb(sic2 yq) cluster(tid )
 	estadd local controls "Yes"
 	estadd local sic2  "Yes"
	estadd local yq "Yes"
 eststo:    reghdfe bid_ask_spread_1_1 num_msa    $controls if tagcq1 ==1 & num_nationality==1, absorb(sic2 num_analysts  yq) cluster(tid )
	estadd local controls "Yes"
	estadd local sic2  "Yes"
	estadd local yq "Yes"
	estadd local num_analysts "Yes"
 
   esttab * using "$tableOutput/r5c1_singlenation", replace  keep(dispers_index num_msa) label stats(controls  sic2  yq num_analysts r2 N, fmt(0 0 0 0 3 %9.0fc) labels("Controls" "Industry FE" "YQ FE" "Number of Analysts FE"  "\(R^{2}\)" "Observations"))	b(4) se(4) varwidth(40) booktabs nonotes      nomtitles star(* 0.10 ** 0.05 *** 0.01) mgroups("Consensus Abs(Error)" "Bid-ask Spread", pattern(1 0  1  0) span prefix(\multicolumn{@span}{c}{) suffix(}) ) 



********************************************************************************
* Figure 2 - Binscatter
********************************************************************************
use $datafolder/scatter_replication, clear
	scatter  sum_nat_cc avg_car_count_fips, graphregion(color(white))
	graph export $tableOutput/scatter.png, replace
	
	binscatter  sum_nat_cc avg_car_count_fips, graphregion(color(white))
	graph export $tableOutput/binscatter.png, replace

********************************************************************************
* Figure 3 - Bootstrap Placebo
********************************************************************************
clear all
set maxvar 20000

set seed 1984
forvalues i=1/10000 {
di `i'

use $datafolder/rfs_gp_replication_pseudo_data, clear
 
 

 
keep  tic msa yq  cc_diff
duplicates drop

duplicates tag tic msa yq, gen(d)
drop if d==1

gen u = uniform()
sort msa yq u
gegen c = count(msa), by(msa yq)
gen boot_cc_diff = cc_diff[_n-1] if msa==msa[_n-1] & yq==yq[_n-1] & tic!=tic[_n-1]
replace boot_cc_diff = cc_diff[_n+c-1] if  boot_cc_diff==. & msa==msa[_n+c-1] & yq==yq[_n+c-1] & tic!=tic[_n+c-1]
drop cc_diff c u 
tempfile random
save `random', replace


use error   no_store_nearby hq TURN12 Size BM ln_analysts experience firm_experience ln_age firm tic yq msa using  $datafolder/rfs_gp_replication_pseudo_data, clear
merge m:1 tic msa yq  using `random', keep(master match) nogen
 
reghdfe error boot_cc_diff no_store_nearby hq TURN12 Size BM ln_analysts experience firm_experience ln_age, absorb(firm##yq msa##yq) cluster(msa)
 outreg2 using  $tableOutput/boot_5_1984.xls, excel bdec(5) tdec(2) bracket  noaster  tstat  nonotes
 }